$(document).ready(function() {

    $('#canvasLeftWrapper a').each(function(index) {
        $(this).attr('rel', 'address:' + makeUrl('/' + $(this).attr('title').toLowerCase()));
    });

    $('a').click(function(e) {
        e.preventDefault();
    });

   $.address.init(function(event) {

   })
   .change(function(event) {
        deepLink = event.value.split('/?')[0];
        if (deepLink.substring(deepLink.length - 1, deepLink.length) == '/') {
            deepLink = deepLink.substring(0, deepLink.length - 1);
        }
        switch(deepLink) {
            case '/multiplayer/newgame':
                if (isMenuOpen()) {
                    closeMenu();
                    emptyLobby();
                }
                createNewGameScreen();

                tempSliderState = lastSliderState;
                lastSliderState = null;
                sliderStateChanged(tempSliderState);
                break;
            case '/multiplayer':
                if (isMenuOpen()) {
                    closeMenu();
                }
                startLobby();
                break;

            case '/lobby':
                if ($('#lobby .newGame').length > 0) {
                    window.clearInterval(OurGame.lobbyInterval);
                    removeLobby();
                    createLobby();
                }
                closeMenu();
                break;

            case '/profile':
                openMenu();
                profile();
                break;
            case '/rankings':
                openMenu();
                rankings();
                break;
            case '/help':
                openMenu();
                help();
                break;
            case '/about':
                openMenu();
                about();
                break;

            default:
                startLobby();
                break;
        }
   });
});